//动态发货仓
getAllWare()
function getAllWare(){ //获取所有发货仓
    var sel = document.getElementById("shippingWarehouse"); //发货仓添加
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url: root.publics.queryWarehouseInfo,
        cache: false, //禁用缓存
        type: "POST",
        dataType:"json",
        async:false,//优先运行
        data: JSON.stringify({
            warehouseCode:""

        }),
        success: function(data){
            console.log(data)
            sessionStorage.setItem("warehouses",JSON.stringify(data))
            //电子券管理通用仓库
            var handStr = '';
            var handp=""//电子券创建
            var sel = document.getElementById("custArea"); //发货仓添加
            for(var i=0;i<data.data.length;i++){
                if(sel!=null){
                    if(data.data[i].warehouseDataType !=2){
                        var option = new Option(data.data[i].warehouseAliasName,data.data[i].warehouseAliasName);
                        sel.options.add(option)
                    }
                }

            }
            var str = "";
            for (var i = 0; i < data.data.length; i++) {
                str += data.data[i].warehouseCode+ ",";
            }
            //去掉最后一个逗号(如果不需要去掉，就不用写)
            if (str.length > 0) {
                str = str.substr(0, str.length - 1);
            }
            sessionStorage.setItem("whosus",str)
            $("#wareHouse").val(str)
            $.each(data.data,function(k,v){
                if(v.warehouseDataType !=2){
                handStr+='<label><input type="checkbox"  name="wareHouse" id="wareHouse'+v.warehouseCode+'" value='+v.warehouseCode+'   disabled/>'+v.warehouseAliasName+'DC&nbsp;&nbsp;</label>'
                handp+='<label><input type="checkbox"  name="wareHouse" value='+v.warehouseCode+' />'+v.warehouseAliasName+'DC&nbsp;&nbsp;</label>'
             }
            })
            $("#checkboxwareHous").html(handStr)
            $("#cartwareHous").html(handp)



            for(var i=0;i<data.data.length;i++){
                if(data.data[i].warehouseDataType !=2){
                if(data.data[i].warehouseAliasName=='北京'){
                    $("#selectVal").append("<option value=" + data.data[i].belongAreaId + " selected>" + data.data[i].warehouseAliasName + "</option>")
                }else {
                    $("#selectVal").append("<option value=" + data.data[i].belongAreaId + ">" + data.data[i].warehouseAliasName + "</option>")
                }
            }
            }

            //运营管理专用仓库
            //品牌馆和品类通用
            var sel = document.getElementById("warehouseCode"); //发货仓添加
            for(var i=0;i<data.data.length;i++){
                if(sel!=null){
                    if(data.data[i].warehouseDataType !=2){
                    var option = new Option(data.data[i].warehouseName,data.data[i].warehouseCode);
                    sel.options.add(option)
                }
            }
                //其余一些

                var yunyinglist=""//查询仓库
                var yunyinglist2=""//编辑仓库
                $.each(data.data,function(k,v){
                    if(v.warehouseDataType !=2){
                    yunyinglist+='<span class="il-b mr-20"><input class="mr-5 checkBox" type="checkbox" checked="checked" inpname="areaName" onclick="changeCang()" onchange="selectCheck()" id="yun'+v.warehouseCode+'" value='+v.warehouseCode+' name='+v.warehouseName+'>'+v.warehouseName+'</span>'
                    yunyinglist2+='<span class="il-b mr-20"><input class="mr-5 checkBox" type="checkbox" onclick="changeCang()" onchange="selectCheck()" inpname="areaName" id="ying'+v.warehouseCode+'" name='+v.warehouseName+' value='+v.warehouseCode+'>'+v.warehouseName+'</span>'
                    }else {
                        yunyinglist+='<span class="il-b mr-20" style="display: none"><input class="mr-5 checkBox" type="checkbox" checked="checked" inpname="areaName" onclick="changeCang() onchange="selectCheck()"" id="yun'+v.warehouseCode+'" value='+v.warehouseCode+' name='+v.warehouseName+'>'+v.warehouseName+'</span>'
                        yunyinglist2+='<span class="il-b mr-20" style="display: none"><input class="mr-5 checkBox" type="checkbox" inpname="areaName" onclick="changeCang()" onchange="selectCheck()" id="ying'+v.warehouseCode+'" name='+v.warehouseName+' value='+v.warehouseCode+'>'+v.warehouseName+'</span>'
                    }

                })
                $("#yunyingwareHous").html(yunyinglist)
                $("#yunyingwareHous2").html(yunyinglist2)


            }
           //区域选择
            var RegionSelection =""
            $.each(data.data,function(k,v){
                if(v.warehouseDataType !=2){
                var warehouseNameSelection=v.warehouseName
                warehouseNameSelection = warehouseNameSelection.match(/(\S*)仓/)[1];
                RegionSelection+='<label ><input type="checkbox" onclick="goodselectionall()" value='+v.warehouseCode+' checked="checked" name="saleArea" inpname="areaName"/>'+warehouseNameSelection+'</label>'
            }
            })
            $("#RegionSelection").html(RegionSelection)
            var RegionSelection2 =""
            $.each(data.data,function(k,v){
          
                var warehouseNameSelection=v.warehouseName
                warehouseNameSelection = warehouseNameSelection.match(/(\S*)仓/)[1];
                RegionSelection2+='<label style="float: left;"><input type="checkbox" onclick="goodselectionall()" value='+v.warehouseCode+' checked="checked" name="saleArea"  inpname="areaName"/>'+warehouseNameSelection+'&nbsp;&nbsp;</label>'
            
            
        })
            $("#RegionSelection2").html(RegionSelection2)
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
        }
    });
    setTimeout(function () {
        selectCheck()
    },500)
}
//全选全不选
function goodselection() {
    var saleArea=$("input[inpname='areaName']")
    if($("#saleAreas").is(':checked')==true){
        for(var i = 0; i < saleArea.length; i++) {
            saleArea[i].checked = true;
        }
    }else {
        for(var i = 0; i < saleArea.length; i++) {
            saleArea[i].checked = false;
        }
    }

  typeof changeCang === 'function'?changeCang():null;

}
//子级选中
function selectCheck() {
    var saleArea=$("input[inpname='areaName']")
    var saleArea2=$("input[inpname='areaName']:checked")
    if(saleArea2.length==saleArea.length){
        $("#saleAreas").prop("checked", true)
    }else {
        $("#saleAreas").prop("checked", false)
    }
}
//退货信息
Returngoods()
function Returngoods(){ //获取所有发货仓
    $.ajax({
        url: root.publics.queryAllReturnAddress,
        cache: false, //禁用缓存
        type: "get",
        dataType:"json",
        async:false,//优先运行
        success: function(data){
            sessionStorage.setItem("returngoods",JSON.stringify(data))

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
        }
    });

}

//商品区域
goodlists()
function goodlists(){
    $.ajax({
        url: root.publics.message,
        cache: false, //禁用缓存
        type: "post",
        dataType:"json",
        async:false,//优先运行
        success: function(data){
            sessionStorage.setItem("regionsss",JSON.stringify(data))
            //商品上下架区域切换
            var goodslist=""
            var doodids=2
            $.each(data.data,function(k,v){
                goodslist+='<label id = "qu'+v.price_area_id+'" style="display: none"><input type="checkbox"   name="saleArea" id = "qua'+v.price_area_id+'"  value='+v.sale_area_id+'>'+v.sale_area_name+'&nbsp;&nbsp;</label>'
            })
            $("#goodswareHous").html(goodslist)

            console.log(data)
            var goodss=""
            var ids=2
            $.each(data.data,function(k,v){
                goodss+='<label><input type="checkbox" onclick="goodselectionall()" value='+v.sale_area_id+' checked="checked" name="saleArea"/>'+v.area_name+'&nbsp;&nbsp;</label>'
            })
            $("#goodsss").html(goodss)


            //商品专用仓库
            var goodss=""
            var goodradio=""
            var ids=2
            var radioid=2
            $.each(data.data,function(k,v){
                goodss+='<label><input type="checkbox" value='+v.sale_area_id+' checked="checked" name="saleArea"/>'+v.sale_area_name+'&nbsp;&nbsp;</label>'
                goodradio+='<input type="radio" name="saleArea" value='+v.sale_area_id+' >'+v.sale_area_name+'&nbsp;'
            })
            /* $("#goodsss").html(goodss)*/
            $("#goodsradio").html(goodradio)
//对接平台专用

            for(var i=0;i<data.data.length;i++){


                if(data.data[i].area_name=='集团'){
                    $("#getArea").append("<option  style='display: none'></option>")
                }else {
                   /* var strarea = data.data[i].area_name;
                    strarea = strarea.match(/(\S*)独有/)[1];*/
                    $("#getArea").append("<option value=" + data.data[i].sale_area_id + " >" + data.data[i].area_name + "</option>")
                }


            }
            var spuinfo=""
            $.each(data.data,function(k,v){
                spuinfo+='<input type="radio" name="saleArea" value='+v.sale_area_id+' >'+v.area_name+'&nbsp;'

            })
            $("#spuinfos").html(spuinfo)

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
        }
    });

}


